﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WmsApp.StaticData.Unity
{
    public class UnitySubject :ISubject
    {
        private string action = string.Empty;
        private IList<BaseObserver> abservers = new List<BaseObserver>();
        #region ISubject Members

        public void Attach(BaseObserver observer)
        {
            abservers.Add(observer);
            observer.ParentControlClosed += (Object sender, EventArgs e) => Detach(observer);
        }

        public void Detach(BaseObserver observer)
        {
            abservers.Remove(observer);
        }

        public void Nofify()
        {
            StaticObjects.RefreshStaticObjects();
            foreach (var baseObserver in abservers)
            {
                if (baseObserver != null && ! baseObserver.PCanClosing.IsDisposed)
                {
                    baseObserver.UpdateData();
                }
            }
        }

        public string SubjectState
        {
            get
            {
                return action;
            }
            set
            {
                action = value;
            }
        }

        #endregion
    }
}
